<!-- 横向布局 -->
<template>
  <el-container class="layout">
    <el-header>
      <div class="logo flx-center">
        <img src="@/assets/logo.svg" alt="logo" />
        <span>Campus Admin</span>
      </div>
      <el-menu
        mode="horizontal"
        :default-active="activeMenu"
        :router="false"
        :unique-opened="true"
      >
        <!-- 只有在这里写 submenu 才能触发 menu 三个点省略 -->
        <template v-for="subItem in menuList" :key="subItem.path">
          <el-sub-menu
            v-if="subItem.children?.length"
            :index="subItem.path"
            :key="subItem.path + 'el-sub-menu'"
          >
            <template #title>
              <el-icon>
                <component :is="subItem.meta.icon"></component>
              </el-icon>
              <span>{{ $t(subItem.meta.title) }}</span>
            </template>
            <SubMenu :menuList="subItem.children" />
          </el-sub-menu>
          <el-menu-item
            v-else
            :index="subItem.path"
            :key="subItem.path + 'el-menu-item'"
            @click="handleClickMenu(subItem)"
          >
            <el-icon>
              <component :is="subItem.meta.icon"></component>
            </el-icon>
            <template #title>
              <span>{{ $t(subItem.meta.title) }}</span>
            </template>
          </el-menu-item>
        </template>
      </el-menu>
      <TopNavbarRight />
    </el-header>
    <MainContainer />
  </el-container>
</template>

<script setup lang="ts" name="layoutTransverse">
import { computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import MainContainer from '@/components/layouts/main-container.vue'
import TopNavbarRight from '@/components/layouts/top-Navbar/top-Navbar-right/index.vue'
import SubMenu from '@/components/layouts/menu/SubMenu.vue'
import type { MenuOptions } from '@/types/menu'
import { useAuthMenuAndButtonStore } from '@/stores'
const authStore = useAuthMenuAndButtonStore()

const route = useRoute()
const router = useRouter()
const activeMenu = computed(() => route.path)
const menuList = authStore.showMenuListGet

const handleClickMenu = (subItem: MenuOptions) => {
  if (subItem.meta.isLink) return window.open(subItem.meta.isLink, '_blank')
  else router.push(subItem.path)
}
</script>

<style scoped lang="scss">
.el-container {
  width: 100%;
  height: 100%;
  .el-header {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 45px;
    padding: 0 15px 0 0;
    background-color: var(--el-bg-color);
    border-bottom: 1px solid var(--el-border-color);
    .logo {
      width: 210px;
      span {
        font-size: 21.5px;
        font-weight: bold;
        color: var(--el-text-color-primary);
        white-space: nowrap;
      }
      img {
        width: 28px;
        object-fit: contain;
        margin-right: 6px;
      }
    }
    :deep(.el-menu) {
      flex: 1;
      overflow: hidden;
      height: 100%;
      border: none;
      // .is-active {
      // 	background-color: var(--el-color-primary) !important;
      // 	border-bottom-color: var(--el-color-primary) !important;
      // 	.el-sub-menu__title {
      // 		color: #ffffff !important;
      // 		background-color: var(--el-color-primary) !important;
      // 		border-bottom-color: var(--el-color-primary) !important;
      // 	}
      // 	&:hover {
      // 		color: #ffffff !important;
      // 	}
      // }
    }
    :deep(.tool-bar-ri) {
      .toolBar-icon,
      .username {
        color: var(--el-text-color-primary);
      }
    }
  }
}
</style>

<style lang="scss">
.transverse {
  // 横向菜单布局
  .el-menu--horizontal {
    .el-menu-item,
    .el-sub-menu {
      .el-sub-menu__title {
        height: 100%;
      }
    }
  }
  .el-menu,
  .el-menu--popup {
    .el-menu-item {
      &.is-active {
        background: var(--el-color-primary-light-9);
      }
    }
  }

  // guide
  #driver-highlighted-element-stage {
    background-color: #606266 !important;
  }
}
</style>
